package com.buddy.syn.method._03;

/**
 * A线程先持有MyObject对象的Lock锁，B线程可以异步调用MyObject对象中的非synchronized方法；
 * 💗 （重点）A线程先持有MyObject对象的Lock锁，B线程如果要调用MyObject对象中的synchronized方法，则需要等待；
 */
public class MyObject {

    synchronized public void methodA(){
        try {
            System.out.println("begin methodA,ThreadName= "+Thread.currentThread().getName());
            Thread.sleep(2000);
            System.out.println("end methodA,endTime = "+System.currentTimeMillis());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public void methodB(){
        try {
            System.out.println("begin methodB,ThreadName= "+Thread.currentThread().getName());
            Thread.sleep(2000);
            System.out.println("end methodB,endTime = "+System.currentTimeMillis());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
